package com.baiiu.filter.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.baiiu.filter.view.FilterCheckedTextView;

import java.util.List;

/**
 * Created by lforxeverc on 16/8/12.
 */
public abstract class SimpleGridTextAdapter<T> extends BaseBaseAdapter<T> {

    private final LayoutInflater inflater;

    public SimpleGridTextAdapter(List<T> list, Context context) {
        super(list, context);
        inflater = LayoutInflater.from(context);
    }

    public static class FilterItemHolder {
        FilterCheckedTextView checkedTextView;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FilterItemHolder holder;
        View tempView = convertView;
        if (tempView == null) {
            tempView = inflater.inflate(com.baiiu.filter.R.layout.gv_item, parent, false);

            holder = new FilterItemHolder();
            holder.checkedTextView = (FilterCheckedTextView) tempView;
//            holder.checkedTextView.setPadding(0, UIUtil.dp(context, 15), 0, UIUtil.dp(context, 15));

            tempView.setTag(holder);
        } else {
            holder = (FilterItemHolder) tempView.getTag();
        }
        if(list != null && list.size() > position) {
            T t = list.get(position);
            holder.checkedTextView.setText(provideText(t));
        }
        return tempView;
    }

    public abstract String provideText(T t);
}